home *** CD-ROM | disk | FTP | other *** search
Text File | 1988-12-09 | 3.4 KB | 178 lines | [TEXT/PJMM] |
- { TransSkel multiple-window demonstration: TextEdit module}
-
- { This module handles a simple TextEdit window, in which text may be}
- { typed and standard Cut/Copy/Paste/Clear operations may be performed.}
- { Undo is not supported, nor is text scrolling.}
-
- { 14 June 1986 Paul DuBois}
- { 7 January 1987 Owen Hartnett }
- { 30 December 1987 OH changed for version 1.03 }
-
- unit MSkelEdit;
-
- interface
-
- uses
- {$IFC UNDEFINED THINK_PASCAL}
- Memtypes, Quickdraw, OSIntf, ToolIntf, PackIntf,
- {$ENDC}
- MultiSkelGlobals, common, TransSkel;
-
- procedure EditWindInit;
- procedure EditWindEditMenu (item: integer);
-
-
- implementation
- { edit menu item numbers }
-
- const
- undo = 1;
- cut = 3;
- copy = 4;
- paste = 5;
- clear = 6;
-
- var
- teEdit: TEHandle; { handle to text window TextEdit record }
-
- procedure Halt;
-
- begin
- TEDispose(teEdit);
- CloseWindow(editWind);
- end;
-
- procedure Idle;
-
- begin
- TEIdle(teEdit); { blink that cursor! }
- end;
-
- procedure key (ch: char; mods: integer);
-
- begin
- TEKey(ch, teEdit);
- end;
-
-
- procedure Mouse (thePt: Point; t: longint; mods: integer);
- begin
- TEClick(thePt, Boolean(BitAnd(mods, shiftKey)), teEdit);
- end;
-
- { Update text window. The update event might be in response to a}
- { window resizing. If so, resize the rects and recalc the linestarts}
- { of the text. To resize the rects, only the right edge of the}
- { destRect need be changed (the bottom is not used, and the left and}
- { top should not be changed). The viewRect should be sized to the}
- { screen.}
-
- procedure Update (resized: Boolean);
-
- var
- r: Rect;
-
- begin
- r := editWind^.portRect;
- EraseRect(r);
- r.left := r.left + 4;
- r.bottom := r.bottom - 2;
- r.top := r.top + 2;
- r.right := r.right - 19;
- if resized then
- begin
- teEdit^^.destRect.right := r.right;
- teEdit^^.viewRect := r;
- TECalText(teEdit);
- end;
- DrawGrowBox(editWind);
- TEUpdate(r, teEdit);
- end;
-
- procedure Activate (active: Boolean);
-
- begin
- DrawGrowBox(editWind);
- if active then
- begin
- TEActivate(teEdit);
- DisableItem(editMenu, undo);
- end
- else
- begin
- TEDeactivate(teEdit);
- EnableItem(editMenu, undo);
- end;
- end;
-
- { Handle Edit menu items for text window}
-
- procedure EditWindEditMenu;
-
- var
- ignore: integer;
- begin
- case item of
- cut:
-
- { cut selection, put in TE Scrap, clear clipboard and put}
- { TE scrap in it}
-
- begin
- TECut(teEdit);
- ignore := ZeroScrap;
- ignore := TEToScrap;
- end;
- copy:
-
- { copy selection to TE Scrap, clear clipboard and put}
- { TE scrap in it}
-
- begin
- TECopy(teEdit);
- ignore := zeroscrap;
- ignore := TEToScrap;
- end;
- paste:
-
- { get clipboard into TE scrap, put TE scrap into edit record}
-
- begin
- ignore := TEFromScrap;
- TEPaste(teEdit);
- end;
- clear:
-
- { delete selection without putting into TE scrap or clipboard}
-
- TEDelete(teEdit);
- otherwise
- ;
- end;
- end;
-
- procedure EditWindInit;
- var
- r: Rect;
- str: str255;
- kludge: longint;
- strptr: Ptr;
-
- begin
- editWind := GetNewWindow(editWindRes, nil, WindowPtr(-1));
- dummy := SkelWindow(editWind, @Mouse, @Key, @Update, @Activate, nil, @Halt, @Idle, true);
- TextFont(0);
- TextSize(0);
- r := editWind^.portRect;
- r.left := r.left + 4;
- r.bottom := r.bottom - 2;
- r.top := r.top + 2;
- r.right := r.right - 19;
- teEdit := TENew(r, r);
- str := 'This is the text editing window.';
- strPtr := @str;
- kludge := longint(strPtr) + 1;
- strPtr := Ptr(kludge);
- TEInsert(strPtr, longint(length(str)), teEdit);
- end;
- end.